home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH20 / car.cs.bak < prev    next >
Encoding:
Text File  |  2004-01-28  |  5.9 KB  |  184 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7.  
  8. // Information extacted from the shape.
  9. //
  10. // Wheel Sequences
  11. //    spring#        Wheel spring motion: time 0 = wheel fully extended,
  12. //                   the hub must be displaced, but not directly animated
  13. //                   as it will be rotated in code.
  14. // Other Sequences
  15. //    steering       Wheel steering: time 0 = full right, 0.5 = center
  16. //    breakLight     Break light, time 0 = off, 1 = breaking
  17. //
  18. // Wheel Nodes
  19. //    hub#           Wheel hub, the hub must be in it's upper position
  20. //                   from which the springs are mounted.
  21. //
  22. // The steering and animation sequences are optional.
  23. // The center of the shape acts as the center of mass for the car.
  24.  
  25. //-----------------------------------------------------------------------------
  26.  
  27. datablock ParticleData(TireParticle)
  28. {
  29.    textureName          = "~/data/particles/dustParticle";
  30.    dragCoefficient      = 2.0;
  31.    gravityCoefficient   = -0.1;
  32.    inheritedVelFactor   = 0.1;
  33.    constantAcceleration = 0.0;
  34.    lifetimeMS           = 1000;
  35.    lifetimeVarianceMS   = 0;
  36.    colors[0]     = "0.46 0.36 0.26 1.0";
  37.    colors[1]     = "0.46 0.46 0.36 0.0";
  38.    sizes[0]      = 0.50;
  39.    sizes[1]      = 1.0;
  40. };
  41.  
  42. datablock ParticleEmitterData(TireEmitter)
  43. {
  44.    ejectionPeriodMS = 10;
  45.    periodVarianceMS = 0;
  46.    ejectionVelocity = 1;
  47.    velocityVariance = 1.0;
  48.    ejectionOffset   = 0.0;
  49.    thetaMin         = 5;
  50.    thetaMax         = 20;
  51.    phiReferenceVel  = 0;
  52.    phiVariance      = 360;
  53.    overrideAdvance = false;
  54.    particles = "TireParticle";
  55. };
  56.  
  57.  
  58. //----------------------------------------------------------------------------
  59.  
  60. datablock WheeledVehicleTire(DefaultCarTire)
  61. {
  62.    // Tires act as springs and generate lateral and longitudinal
  63.    // forces to move the vehicle. These distortion/spring forces
  64.    // are what convert wheel angular velocity into forces that
  65.    // act on the rigid body.
  66.    shapeFile = "~/data/models/vehicles/wheel.dts";
  67.    staticFriction = 4;
  68.    kineticFriction = 1.25;
  69.  
  70.    // Spring that generates lateral tire forces
  71.    lateralForce = 18000;
  72.    lateralDamping = 4000;
  73.    lateralRelaxation = 1;
  74.  
  75.    // Spring that generates longitudinal tire forces
  76.    longitudinalForce = 18000;
  77.    longitudinalDamping = 4000;
  78.    longitudinalRelaxation = 1;
  79. };
  80.  
  81. datablock WheeledVehicleSpring(DefaultCarSpring)
  82. {
  83.    // Wheel suspension properties
  84.    length = 0.85;             // Suspension travel
  85.    force = 3000;              // Spring force
  86.    damping = 600;             // Spring damping
  87.    antiSwayForce = 3;         // Lateral anti-sway force
  88. };
  89.  
  90. datablock WheeledVehicleData(DefaultCar)
  91. {
  92.    category = "Vehicles";
  93.    className = "Car";
  94.    shapeFile = "~/data/models/vehicles/runabout.dts";
  95.    emap = true;
  96.  
  97.    maxDamage = 1.0;
  98.    destroyedLevel = 0.5;
  99.  
  100.    maxSteeringAngle = 0.785;  // Maximum steering angle, should match animation
  101.    tireEmitter = TireEmitter; // All the tires use the same dust emitter
  102.  
  103.    // 3rd person camera settings
  104.    cameraRoll = true;         // Roll the camera with the vehicle
  105.    cameraMaxDist = 6;         // Far distance from vehicle
  106.    cameraOffset = 1.5;        // Vertical offset from camera mount point
  107.    cameraLag = 0.1;           // Velocity lag of camera
  108.    cameraDecay = 0.75;        // Decay per sec. rate of velocity lag
  109.  
  110.    // Rigid Body
  111.    mass = 200;
  112.    massCenter = "0 -0.5 0";    // Center of mass for rigid body
  113.    massBox = "0 0 0";         // Size of box used for moment of inertia,
  114.                               // if zero it defaults to object bounding box
  115.    drag = 0.6;                // Drag coefficient
  116.    bodyFriction = 0.6;
  117.    bodyRestitution = 0.4;
  118.    minImpactSpeed = 5;        // Impacts over this invoke the script callback
  119.    softImpactSpeed = 5;       // Play SoftImpact Sound
  120.    hardImpactSpeed = 15;      // Play HardImpact Sound
  121.    integration = 4;           // Physics integration: TickSec/Rate
  122.    collisionTol = 0.1;        // Collision distance tolerance
  123.    contactTol = 0.1;          // Contact velocity tolerance
  124.  
  125.    // Engine
  126.    engineTorque = 4000;       // Engine power
  127.    engineBrake = 600;         // Braking when throttle is 0
  128.    brakeTorque = 8000;        // When brakes are applied
  129.    maxWheelSpeed = 30;        // Engine scale by current speed / max speed
  130.  
  131.    // Energy
  132.    maxEnergy = 100;
  133.    jetForce = 3000;
  134.    minJetEnergy = 30;
  135.    jetEnergyDrain = 2;
  136.  
  137.    // Sounds
  138.    jetSound = CarThrustSound;
  139.    engineSound = CarEngineSound;
  140.    squealSound = CarSquealSound;
  141.    softImpactSound = CarSoftImpactSound;
  142.    hardImpactSound = CarHardImpactSound;
  143.    wheelImpactSound = CarWheelImpactSound;
  144.  
  145. //   explosion = VehicleExplosion;
  146. };
  147.  
  148.  
  149. //-----------------------------------------------------------------------------
  150.  
  151. function WheeledVehicleData::create(%block)
  152. {
  153.    %obj = new WheeledVehicle() {
  154.       dataBlock = %block;
  155.       mountable = true;
  156.    };
  157.    return(%obj);
  158. }
  159.  
  160. //-----------------------------------------------------------------------------
  161.  
  162. function WheeledVehicleData::onAdd(%this,%obj)
  163. {
  164.    // Setup the car with some defaults tires & springs
  165.    for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
  166.       %obj.setWheelTire(%i,DefaultCarTire);
  167.       %obj.setWheelSpring(%i,DefaultCarSpring);
  168.       %obj.setWheelPowered(%i,false);
  169.    }
  170.  
  171.    // Steer front tires
  172.    %obj.setWheelSteering(0,1);
  173.    %obj.setWheelSteering(1,1);
  174.  
  175.    // Only power the two rear wheels...
  176.    %obj.setWheelPowered(2,true);
  177.    %obj.setWheelPowered(3,true);
  178. }
  179.  
  180. function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
  181. {
  182.    // Collision with other objects, including items
  183. }
  184.